//package com.colin.library.base;
//
//import android.content.Context;
//import android.support.v7.widget.GridLayoutManager;
//import android.support.v7.widget.RecyclerView;
//import android.support.v7.widget.StaggeredGridLayoutManager;
//import android.view.LayoutInflater;
//import android.view.View;
//import android.view.ViewGroup;
//
//import com.colin.library.base.BaseViewHolder;
//import com.colin.library.base.R;
//import com.colin.library.listener.OnRecyclerItemClickListener;
//import com.colin.library.listener.OnRecyclerLoadMoreListener;
//
//import java.util.List;
//
///**
// * Created by Administrator on 2017/9/15.
// */
//
//public abstract class BaseRecyclerAdapter<T> extends RecyclerView.Adapter<BaseViewHolder> {
//    protected Context mContext;
//    protected List<T> mItemList;
//
//    protected LayoutInflater mLayoutInflater;
//    protected OnRecyclerItemClickListener mOnRecyclerItemClickListener;
//    protected OnRecyclerLoadMoreListener mOnRecyclerLoadMoreListener;
//
//    protected boolean showEmpty = true;
//    protected boolean showMore = false;
//    protected boolean showFoot = false;
//    public final static int VIEW_TYPE_EMPTY = -1;
//    public final static int VIEW_TYPE_MORE = -2;
//    public final static int VIEW_TYPE_HEAD = -3;
//    public final static int VIEW_TYPE_FOOT = -4;
//
//    public final static int VIEW_MORE_STATE_LOADING = 0;//显示
//    public final static int VIEW_MORE_STATE_FINISH = 1;//隐藏
//    public final static int VIEW_MORE_STATE_CLICK = 2;//显示
//    protected int viewMoreState = VIEW_MORE_STATE_FINISH;
//
//    public BaseRecyclerAdapter(Context context, List<T> itemList) {
//        this.mContext = context;
//        this.mItemList = itemList;
//        this.mLayoutInflater = LayoutInflater.from(context);
//    }
//
//    public void setViewMoreState(int viewMoreState) {
//        this.viewMoreState = viewMoreState;
//    }
//
//    public void setOnRecyclerItemClickListener(OnRecyclerItemClickListener onRecyclerItemClickListener) {
//        mOnRecyclerItemClickListener = onRecyclerItemClickListener;
//    }
//
//    public void setOnRecyclerLoadMoreListener(OnRecyclerLoadMoreListener onRecyclerLoadMoreListener) {
//        mOnRecyclerLoadMoreListener = onRecyclerLoadMoreListener;
//    }
//
//    /**
//     * 显示加载更多  1 接口不为空OnRecyclerLoadMoreListener ，状态 是不是VIEW_MORE_STATE_FINISH
//     *
//     * @return
//     */
//    public boolean isShowMore() {
//        return showMore = null != mOnRecyclerLoadMoreListener;
//    }
//
//    public boolean isShowFoot() {
//        return showFoot;
//    }
//
//
//    @Override
//    public int getItemCount() {
//        if (isEmpty() && showEmpty) {
//            return 1;
//        } else if (!isEmpty() && isShowMore()) {
//            return mItemList.size() + 1;
//        } else {
//            return mItemList.size();
//        }
//    }
//
//    public boolean isEmpty() {
//        return null == mItemList || mItemList.size() == 0;
//    }
//
//    @Override
//    public int getItemViewType(int position) {
//        if (isEmpty() && showEmpty) {
//            return VIEW_TYPE_EMPTY;
//        }
//        if (isShowMore() && position + 1 == getItemCount()) {
//            return VIEW_TYPE_MORE;
//        }
//        return super.getItemViewType(position);
//    }
//
//    @Override
//    public BaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
//        if (viewType == VIEW_TYPE_EMPTY) {
//            return new BaseViewHolder(mLayoutInflater.inflate(R.layout.layout_list_empty, parent, false));
//        }
//        if (viewType == VIEW_TYPE_MORE) {
//            return new BaseViewHolder(mLayoutInflater.inflate(R.layout.load_more_footview_layout, parent, false));
//        }
//        return new BaseViewHolder(mLayoutInflater.inflate(bindLayoutRes(viewType), parent, false));
//    }
//
//    @Override
//    public void onBindViewHolder(BaseViewHolder holder, int position) {
//        int viewType = getItemViewType(position);
//        switch (viewType) {
//            case VIEW_TYPE_EMPTY:
//                break;
//            case VIEW_TYPE_MORE:
////                mOnRecyclerLoadMoreListener.loadMore();
//                break;
//        }
//    }
//
//    @Override
//    public void onBindViewHolder(BaseViewHolder holder, int position, List<Object> payloads) {
//        super.onBindViewHolder(holder, position, payloads);
//    }
//
//    protected abstract int bindLayoutRes(int viewType);
//
//
//    public class AdapterClickListener implements View.OnClickListener {
//        private T t;
//        private int position;
//
//        public AdapterClickListener(T t, int position) {
//            this.t = t;
//            this.position = position;
//        }
//
//        @Override
//        public void onClick(View v) {
//            if (null != mOnRecyclerItemClickListener) {
//                mOnRecyclerItemClickListener.itemClick(v, t, position);
//            }
//        }
//    }
//
//    /**
//     * 处理瀑布流 添加空布局 和 更多
//     *
//     * @param holder
//     */
//    @Override
//    public void onViewAttachedToWindow(BaseViewHolder holder) {
//        super.onViewAttachedToWindow(holder);
//        int type = holder.getItemViewType();
//        if (type == VIEW_TYPE_EMPTY || type == VIEW_TYPE_MORE) {
//            setFullSpan(holder);
//        }
//    }
//
//    /**
//     * @param holder
//     */
//    protected void setFullSpan(RecyclerView.ViewHolder holder) {
//        if (holder.itemView.getLayoutParams() instanceof StaggeredGridLayoutManager.LayoutParams) {
//            StaggeredGridLayoutManager.LayoutParams params = (StaggeredGridLayoutManager.LayoutParams) holder.itemView.getLayoutParams();
//            params.setFullSpan(true);
//        }
//    }
//
//    /**
//     * 处理网格布局 添加空布局 和 更多
//     *
//     * @param recyclerView
//     */
//    @Override
//    public void onAttachedToRecyclerView(RecyclerView recyclerView) {
//        super.onAttachedToRecyclerView(recyclerView);
//        RecyclerView.LayoutManager manager = recyclerView.getLayoutManager();
//        if (manager instanceof GridLayoutManager) {
//            final GridLayoutManager gridManager = ((GridLayoutManager) manager);
//            gridManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
//                @Override
//                public int getSpanSize(int position) {
//                    int type = getItemViewType(position);
//                    return (type == VIEW_TYPE_EMPTY || type == VIEW_TYPE_MORE) ? gridManager.getSpanCount() : 1;
//                }
//            });
//        }
//    }
//}
